﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using BrokerBase.Lib.Product;
using System.Xml.Linq;
using System.Xml;
using System.Windows.Markup;

namespace Broker.Mgr.ViewModel
{
    public static class GridTemplateUtil
    {
        public static DataTemplate[] CreateGridHeadTemplate(IList<IRateFactor> factors)
        {

            int count = factors[0].Items.Split(';').Count();

            DataTemplate[] dts = new DataTemplate[count];
            XElement [] xEls=new XElement[count];

            foreach (IRateFactor rf in factors)
            {
                string[] items = rf.Items.Split(';');

                for (int i = 0; i < count; i++)
                {
                    XNamespace ns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
                    if (xEls[i] == null)
                    {
                        
                        xEls[i] = new XElement(ns + "DataTemplate",
                            new XAttribute("xmlns", "http://schemas.microsoft.com/winfx/2006/xaml/presentation"),
                            new XElement(ns + "StackPanel", new XAttribute("Orientation", "Vertical"))
                            );
                    }

                    bool b = xEls[i].HasElements;

                    XElement xStackPanel = xEls[i].Element(ns+"StackPanel");

                    XElement xTextBlock=new XElement(ns+"TextBlock",new XAttribute("Text",items[i]));

                }

            }

            for(int i =0;i<count;i++)
            {
                XmlReader xr = xEls[i].CreateReader();

                dts[i] = XamlReader.Load(xr) as DataTemplate;
            }

            return dts;
        }
    }
}
